{layout name="layout" /}
<style>
    .none-image{
        background-image:url("/static/layuiadmin/style/res/wechat/image.png");
    }
</style>
<div class="layui-bg-white">
    <div class="layui-main layui-contianer">
        <div class="layui-fluid">
            <div class="layui-row">
                <div class="layui-col-sm5">
                    <form class="layui-form" action="/admin/wechatconfig/update">
                        <div class="layui-form-item">
                            <label class="layui-form-label">公众号名称</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$model->name}" name="name" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">微信号</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$model->wechatId}" name="wechatId" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">公众号原始id</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$model->primitiveId}" name="primitiveId" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">微信验证TOKEN</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$model->token}" name="token" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">EncodingAESKey</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$model->encoding}" name="encoding" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">接口地址</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$model->targetUrl}" name="targetUrl" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">消息加解密方式</label>
                            <div class="layui-input-block">
                            <?php
                            $enabled=$model->encryptionType??0;
                            ?>
                                <input type="radio" name="encryptionType" value="0" title="明文模式" {$enabled ==0 ?"checked":""}>
                                <input type="radio" name="encryptionType" value="1" title="兼容模式" {$enabled ==1 ?"checked":""}>
                                <input type="radio" name="encryptionType" value="2" title="安全模式" {$enabled ==2 ?"checked":""}>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">公众号类型</label>
                            <div class="layui-input-block">
                            <?php
                            $enabled=$model->wechatType??0;
                            ?>
                                <input type="radio" name="wechatType" value="0" title="服务号" {$enabled ==0 ?"checked":""}>
                                <input type="radio" name="wechatType" value="1" title="订阅号" {$enabled ==1 ?"checked":""}>
                            </div>
                        </div>

                        <div class="layui-form-item" data-image="qrcode">
                            <label class="layui-form-label">公众号二维码</label>
                            <div class="layui-input-inline">
                                <button type="button" class="layui-btn" data-btn="openImages">选择图片</button>
                                <input type="hidden" id="qrCode" name="qrCode" value="{$model->qrCode|default=''}"
                                    autocomplete="off" class="layui-input">
                                <div class="layui-upload-list none-image" style="width:100px;height:80px;">
                                    <img class="layui-upload-img" style="width:auto;height:auto;max-width=100%;max-height:100%;" id="demo1" src="{$model->qrCode|default=''}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item" data-image="logo">
                            <label class="layui-form-label">logo</label>
                            <div class="layui-input-inline">
                                <button type="button" class="layui-btn" data-btn="openImages">选择图片</button>
                                <input type="hidden" id="logo" name="logo" value="{$model->logo|default=''}"
                                    autocomplete="off" class="layui-input">
                                <div class="layui-upload-list none-image" style="width:100px;height:80px;">
                                    <img class="layui-upload-img" style="width:auto;height:auto;max-width=100%;max-height:100%;" id="demo1" src="{$model->logo|default=''}">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <input type="hidden" name="id">
                            <input type="button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="zbc-wechat-submit" value="确认">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','layer', 'form','upload'],function(){
        var $ = layui.$
            , form = layui.form
            , layer=layui.layer
            , laytpl=layui.laytpl
            , view=layui.view
            , upload = layui.upload;

        //监听提交
        form.on('submit(zbc-wechat-submit)', function(data){
            var $this=$(this);
            var hasRequest=$this.attr("request");
            if(hasRequest) return ;

            if(!hasRequest) $this.attr("request",true);

            view.req({
              url:"/admin/wechatconfig/update",
              data: data.field,
              method: 'post',
              success: function (result) {
                if (result.data) {
                  layer.msg("已完成");
                  location.reload();
                } else {
                  layer.msg(result.msg, { icon: 4 });
                  $this.attr("request",false);
                }
              },
              error:function(){
                $this.attr("request",false);
              }
            })
            return false;
        });

        $(document).on("click","[data-btn=openImages]",function(){
                var parentLayer=parent.layer;
                var $this=$(this);
                parentLayer.open({
                title: '图片列表',
                type:2,
                area:['1024px', '600px'],
                content: '/admin/wechatArticle/images',
                btn:["确定","取消"],
                yes:function(index,layero){
                    var selected=layero.find("iframe").contents().find("[data-selected=true]")
                    var id=selected.attr("data-id");
                    var path=selected.attr("data-path");
                    var $parent=$this.parents("[data-image]");
                    if($parent){
                        $parent.find("input").val(path);
                        $parent.find("img").attr("src",path);
                    }
                    parentLayer.close(index);
                }
            }); 
        });

       
    })

</script>